package jjoms.model.info;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class InfoDAOImpl implements InfoDAO {
	@Resource(name = "sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;
	
	@Override
	public InfoVO cateforyFindByKeyword(String keyword) {
		return sqlSessionTemplate.selectOne("info.cateforyFindByKeyword", keyword);
	}
	@Override
	public InfoVO divisionFindByKeyword(String keyword) {
		return sqlSessionTemplate.selectOne("info.divisionFindByKeyword", keyword);
	}

	@Override
	public InfoVO sectionFindByKeyword(String keyword) {
		return sqlSessionTemplate.selectOne("info.sectionFindByKeyword", keyword);
	}
	
	@Override
	public List<String> getCategoryKind() {
		return sqlSessionTemplate.selectList("info.getCategoryKind");
	}

	@Override
	public List<String> getDivisionKind(String category) {
		return sqlSessionTemplate.selectList("info.getDivisionKind", category);
	}

	@Override
	public void infoRegiseter(InfoVO infoVO) {
		sqlSessionTemplate.insert("info.infoRegiseter", infoVO);
	}

	@Override
	public void insertDivision(InfoVO infoVO) {
		System.out.println("insertDivision : " + infoVO);
		sqlSessionTemplate.update("info.insertDivision", infoVO);
	}

	@Override
	public void insertSection(InfoVO infoVO) {
		sqlSessionTemplate.insert("info.insertSection", infoVO);
	}

	@Override
	public void infoUpdate(InfoVO infoVO, String beforeKeyword) {
		HashMap map = new HashMap<>();
		map.put("infoVO", infoVO);
		map.put("beforeKeyword", beforeKeyword);
		sqlSessionTemplate.update("info.infoUpdate", map);
	}

	@Override
	public void categoryUpdate(InfoVO infoVO, String beforeKeyword) {
		HashMap map = new HashMap<>();
		map.put("infoVO", infoVO);
		map.put("beforeKeyword", beforeKeyword);
		sqlSessionTemplate.update("info.categoryUpdate", map);
	}

	@Override
	public void deleteDivision(String keyword) {
		sqlSessionTemplate.delete("info.deleteDivision", keyword);
	}
	
	@Override
	public void deleteSection(String keyword) {
		sqlSessionTemplate.delete("info.deleteSection", keyword);
	}

	@Override
	public void infoDelete(String keyword) {
		sqlSessionTemplate.delete("info.infoDelete", keyword);
	}

	@Override
	public List<String> getSectionKind(String keyword) {
		return sqlSessionTemplate.selectList("info.getSectionKind", keyword);
	}

	@Override
	public List<String> getSection(String category) {
		return sqlSessionTemplate.selectList("info.getSection", category);
	}

	
	
}
